package xyz.gzdxc.common.mysql.repository;

import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import xyz.gzdxc.common.mysql.entity.UserTokenEntity;

import java.util.List;
import java.util.Optional;

@Repository
public interface UserTokenRepository extends CrudRepository<UserTokenEntity, Long> {

    /**
     * get the user data by id
     * @param id
     * @return
     */
    @Override
    Optional<UserTokenEntity> findById(Long id);

    /**
     * get the priv list by user id
     */
    @Query("select p.priv_code as privCode from xh_cm_group_user gu join xh_cm_group_priv gp on (gu.del_status='0' and gp.del_status='0' and gu.group_id=gp.group_id) join xh_cm_priv p on (p.del_status='0' and p.id=gp.priv_id) where gu.user_id = :userId")
    List<String> getPrivListByUserId(@Param("userId") Long userId);
}
